<template>
    <div class="app-container">
        <section>
            <div class="contentBox">
                <div class="title">
                    <span>{{$route.query.title}}</span>
                </div>
                <div class="content">
                    <el-form ref="form" :model="form"  class="form"  label-width="110px">
                        <el-form-item label="项目分类名称"  style="width:100%">
                            <el-input v-model="form.name" placeholder="请输入"></el-input>
                        </el-form-item>
                        <!-- <el-form-item label="服务项目名称" style="width:100%"  v-for="(ele,index) in list" :key="index"> 
                            <el-input v-model="form.username" placeholder="请输入"></el-input>
                            <i class="el-icon-circle-plus-outline" @click="add()"></i>
                            <i class="el-icon-remove-outline" @click="dele(index)"></i>
                        </el-form-item> -->
                    </el-form>
                    <div style="margin-top:40px">
                        <el-button type="primary" style="width:143px" @click="save">确定</el-button>
                        <el-button style="width:143px" @click="$router.go(-1)">取消</el-button>
                    </div>
                </div>
            </div>
        </section>
    </div>
</template>
<script>
export default {
    data() {
        return {
            value1:false,
            list:[{}],
            form: {
               name:'',
               id:''
            },
            roleList: []
        }
    },
    created() {
        if (this.$route.query.id) {
            this.form.id = this.$route.query.id
            this.getDetails()
        }
        this.$route.meta.title = this.$route.query.title
    },
    mounted() {
    },
    methods: {
        add(){
            this.list.push({})
        },
        dele(index){
            this.list.splice(index,1)   
        },
        async getDetails() {
            let {code,data} = await this.$Http.getCate(this.form)
            if (code) {
                this.form.name = data.name
            }
        },
       async save() {
           if(!this.form.name){
               this.$message.error('请输入项目分类名称')
               return
           }
            let {code,data} = await this.$Http.setCate(this.form)
            if (code) {
                if (this.form.id) {
                    this.$message.success('编辑成功')
                } else {
                    this.$message.success('添加成功')
                }
                this.$router.go(-1)
            }
        },
    }
}
</script>

<style lang="scss" scoped>
.app-container {
    section {
        .contentBox {
            background: #fff;
            border-radius: 8px;
            padding: 0px 24px 20px;
            min-width: 900px;
            min-height: calc(100vh - 165px );
            .title {
                line-height: 70px;
                font-size: 18px;
                font-weight: 600;
                color: #383b40;
                .el-icon-close {
                    cursor: pointer;
                }
            }
        }
        .content {
            max-width:800px;
            height: 100%;
            .form {
                display: flex;
                flex-wrap: wrap;
                justify-content: space-between;
            }
        }
    }
}
::v-deep{
    .el-input{
        width: 250px;
    }
    .el-icon-circle-plus-outline,.el-icon-remove-outline{
        color: #999;
        font-size: 26px;
        margin: 0 5px;
    }
     .el-icon-circle-plus-outline{
        margin-left: 20px;
    }
    .el-icon-remove-outline{
        color: #f00;
    }
    .el-form-item__content{
        display: flex;
        align-items: center;
    }
}
</style>